<?php
if (!defined('SMF'))
	die('Hacking attempt...');
	
global $smcFunc, $txt, $scripturl, $settings, $user_info;
global $dbtables;
global $allow_ibank;

// Verify user login, if CheckLogin() returns false return to the calling script/function
if (CheckLogin() == false)
	return;

bigtitle($txt['bnt_planet_title']);

//-------------------------------------------------------------------------------------------------

// Pull player info into $playerinfo.
$result = $smcFunc['db_query']('', '
	SELECT *
	FROM {raw:db_ships}
	WHERE user_id = {int:user_id}
	LIMIT 1',
	array(
		'db_ships' => $dbtables['ships'],
		'user_id' => $user_info['id'],
	)
);
$playerinfo = $smcFunc['db_fetch_assoc']($result);
$smcFunc['db_free_result']($result);

$result = $smcFunc['db_query']('', '
	SELECT *
	FROM {raw:db_ibank_accounts}
	WHERE ship_id = {int:ship_id}
	LIMIT 1',
	array(
		'db_ibank_accounts' => $dbtables['ibank_accounts'],
		'ship_id' => $playerinfo['ship_id']
	)
);
$account = $smcFunc['db_fetch_assoc']($result);
$smcFunc['db_free_result']($result);

echo '
	<center>
	<img src="', $settings['images_url'], '/bnt/div1.gif">
	<table width="600" height="350" border="0">
		<tr>
			<td align="center" background="', $settings['images_url'], '/bnt/IGBscreen.gif">
				<table background="" width="520" height="300" border="0">';

if (!$allow_ibank)
{
	IGB_error($txt['bnt_igb_malfunction'], 'main');
	return;
}

$command = (isset($_GET['command'])) ? $_GET['command'] : '';

switch ($command)
{
	// Main menu.
	case 'login':
		IGB_login($playerinfo,$account);
		continue;
	
	// Withdraw menu.
	case 'withdraw':
		IGB_withdraw($playerinfo,$account);
		continue;
	
	// Withdraw operation.
	case 'withdraw2':
		IGB_withdraw2($playerinfo,$account);
		continue;
	
	// Deposit menu.
	case 'deposit':
		IGB_deposit($playerinfo,$account);
		continue;
	
	// Deposit operation.
	case 'deposit2': 
		IGB_deposit2($playerinfo,$account);
		continue;
	
	// Main transfer menu.
	case 'transfer':
		IGB_transfer($playerinfo,$account);
		continue;
	
	// Specific transfer menu (ship or planet).
	case 'transfer2': 
		IGB_transfer2($playerinfo,$account);
		continue;
	
	// Transfer operations.
	case 'transfer3': 
		IGB_transfer3($playerinfo,$account);
		continue;
	
	// Consolidate menu.
	case 'consolidate': 
		IGB_consolidate($playerinfo);
		continue;
	
	// Consolidate compute.
	case 'consolidate2':
		IGB_consolidate2($playerinfo);
		continue;
	
	// Consolidate operations.
	case 'consolidate3': 
		IGB_consolidate3($playerinfo);
		continue;
	
	case 'loans': //loans menu
		IGB_loans($playerinfo,$account);
		continue;
		
	case 'borrow': //borrow operation
		IGB_borrow($playerinfo,$account);
		continue;
		
	case 'repay': //repay operation
		IGB_repay($playerinfo,$account);
		continue;
		
	default:
		echo '
					<tr>
						<td width="25%" valign="bottom">
							<a href="', $scripturl, '?action=blacknova;sa=main"><font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_quit'], '</a>
						</td>
						<td width="50%">
							<font size="2" face="courier new" color="#00FF00">
							<pre>
IIIIIIIIII          GGGGGGGGGGGGG    BBBBBBBBBBBBBBBBB
I::::::::I       GGG::::::::::::G    B::::::::::::::::B
I::::::::I     GG:::::::::::::::G    B::::::BBBBBB:::::B
II::::::II    G:::::GGGGGGGG::::G    BB:::::B     B:::::B
I::::I     G:::::G       GGGGGG      B::::B     B:::::B
I::::I    G:::::G                    B::::B     B:::::B
I::::I    G:::::G                    B::::BBBBBB:::::B
I::::I    G:::::G    GGGGGGGGGG      B:::::::::::::BB
I::::I    G:::::G    G::::::::G      B::::BBBBBB:::::B
I::::I    G:::::G    GGGGG::::G      B::::B     B:::::B
I::::I    G:::::G        G::::G      B::::B     B:::::B
I::::I     G:::::G       G::::G      B::::B     B:::::B
II::::::II    G:::::GGGGGGGG::::G    BB:::::BBBBBB::::::B
I::::::::I     GG:::::::::::::::G    B:::::::::::::::::B
I::::::::I       GGG::::::GGG:::G    B::::::::::::::::B
IIIIIIIIII          GGGGGG   GGGG    BBBBBBBBBBBBBBBBB
							</pre>
							<center>
								<p>', $txt['bnt_igb_title'], '</p>
								<br>&nbsp;
							</center>
							</font>
						</td>
						<td width="25%" valign="bottom" align="right"><font size="2" color="#00FF00" face="courier new">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_login'], '</a>
						</td>';
}

echo '
					</tr>
				</table>
			</td>
		</tr>
	</table>
<img src="', $settings['images_url'], '/bnt/div2.gif">
</center>';

// IGB Functions

function IGB_login($playerinfo,$account)
{
	global $txt, $scripturl;

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_welcometoigb'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_accountholder'], ' :<br><br>
							', $txt['bnt_igb_shipaccount'], ' :<br>
							', $txt['bnt_igb_igbaccount'], '&nbsp;&nbsp;:
						</td>
						<td align="left">
							<font size="2" face="courier new" color="#00FF00">', $playerinfo['character_name'], '&nbsp;&nbsp;<br><br>
							', NUMBER($playerinfo['credits']), ' ', $txt['bnt_igb_credit_symbol'], '<br>
							', NUMBER($account['balance']), ' ', $txt['bnt_igb_credit_symbol'], '<br>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center"><font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_operations'], '<br>
						---------------------------------<br><br>
						<a href="', $scripturl, '?action=blacknova;sa=igb;command=withdraw">', $txt['bnt_igb_withdraw'], '</a><br>
						<a href="', $scripturl, '?action=blacknova;sa=igb;command=deposit">', $txt['bnt_igb_deposit'], '</a><br>
						<a href="', $scripturl, '?action=blacknova;sa=igb;command=transfer">', $txt['bnt_igb_transfer'], '</a><br>
						<a href="', $scripturl, '?action=blacknova;sa=igb;command=loans">', $txt['bnt_igb_loans'], '</a><br>&nbsp;
					</td>
				</tr>
				<tr valign="bottom">
					<td>
						<font size="2" face="courier new" color="#00FF00"><a href="', $scripturl, '?action=blacknova;sa=igb">', $txt['bnt_igb_back'], '</a>
					</td>
					<td align=right>
						<font size="2" face="courier new" color="#00FF00">&nbsp;<br><a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
					</td>
				</tr>';
}

function IGB_withdraw($playerinfo,$account)
{

	global $txt, $scripturl;
	
	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_withdrawfunds'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_fundsavailable'], ' :
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($account['balance']), ' C<br>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_selwithdrawamount'], ' :
						</td>
						<td align=right>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=withdraw2" method="post">
								<input class="term" type="text" size="15" maxlength="20" name="amount" value="0"><br><br>
								<input class="term" type="submit" value="', $txt['bnt_igb_withdraw'], '">
							</form>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br>
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';

}

function IGB_withdraw2($playerinfo,$account)
{
	global $smcFunc, $txt, $scripturl;
	global $dbtables;

	$amount = (isset($_POST['amount'])) ? $_POST['amount'] : '';
	
	$amount = StripNonNum($amount);
  
	if (($amount * 1) != $amount)
	{
		IGB_error($txt['bnt_igb_invalidwithdrawinput'], "igb;command=withdraw");
		return;
	}

	if ($amount == 0 || empty($amount) || $amount < 0)
	{
		IGB_error($txt['bnt_igb_nozeroamount3'], "igb;command=withdraw");
		return;
	}

	if ($amount > $account['balance'])
	{
		IGB_error($txt['bnt_igb_notenoughcredits'], "igb;command=withdraw");
		return;
	}

	$account['balance'] -= $amount;
	$playerinfo['credits'] += $amount;

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_operationsuccessful'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount), ' ', $txt['bnt_igb_creditstoyourship'], '
							</font>
						</td>
					<tr>
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_accounts'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_shipaccount'], ' :<br>
							', $txt['bnt_igb_igbaccount'], ' :
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($playerinfo['credits']), ' C<br>
							', NUMBER($account['balance']), ' C
							</font>
						</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br>
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
						</td>
					</tr>';
					
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ibank_accounts}
		SET balance = balance - {float:amount}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ibank_accounts' => $dbtables['ibank_accounts'],
			'amount' => floatval($amount),
			'ship_id' => $playerinfo['ship_id']
		)
	);
	
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ships}
		SET credits = credits + {float:amount}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ships' => $dbtables['ships'],
			'amount' => floatval($amount),
			'ship_id' => $playerinfo['ship_id']
		)
	);				
}

function IGB_deposit($playerinfo,$account)
{
	global $txt, $scripturl;

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_depositfunds'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_fundsavailable'], ' :
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($playerinfo['credits']), ' C<br>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_seldepositamount'], ' :</td>
							<td align="right">
								<form action="', $scripturl, '?action=blacknova;sa=igb;command=deposit2" method="post">
									<input class="term" type="text" size="15" maxlength="20" name="amount" value="0"><br><br>
									<input class="term" type="submit" value="', $txt['bnt_igb_deposit'], '">
								</form>
							</td>
						</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00"><a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a></font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br>
								<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';

}

function IGB_deposit2($playerinfo,$account)
{
	global $smcFunc, $txt, $scripturl;
	global $dbtables;
	
	$amount = (isset($_POST['amount'])) ? $_POST['amount'] : '';

	$amount = StripNonNum($amount);
	
	if (($amount * 1) != $amount)
	{
		IGB_error($txt['bnt_igb_invaliddepositinput'], "igb.php?command=deposit");
		return;
	}

	if ($amount == 0 || empty($amount) || $amount < 0)
	{
		IGB_error($txt['bnt_igb_nozeroamount2'], "igb;command=deposit");
		return;
	}

	if ($amount > $playerinfo['credits'])
	{
		IGB_error($txt['bnt_igb_notenoughcredits'], "igb;command=deposit");
		return;
	}

	$account['balance'] += $amount;
	$playerinfo['credits'] -= $amount;

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_operationsuccessful'], '<br>
							---------------------------------
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount), ' ', $txt['bnt_igb_creditstoyou'], '
						</td>
					<tr>
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_accounts'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_shipaccount'], ' :<br>
							', $txt['bnt_igb_igbaccount'], ' :
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($playerinfo['credits']), ' C<br>
							', NUMBER($account['balance']), ' C
							</font>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br>
							<a href="', $scripturl, '?action=blacknova;sa=main.php">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';
					
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ibank_accounts}
		SET balance = balance + {float:amount}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ibank_accounts' => $dbtables['ibank_accounts'],
			'amount' => floatval($amount),
			'ship_id' => $playerinfo['ship_id']
		)
	);
	
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ships}
		SET credits = credits - {float:amount}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ships' => $dbtables['ships'],
			'amount' => floatval($amount),
			'ship_id' => $playerinfo['ship_id']
		)
	);
}

function IGB_transfer($playerinfo,$account)
{
	global $smcFunc, $txt, $scripturl;
	global $dbtables;
	
	$result = $smcFunc['db_query']('', '
		SELECT character_name, ship_id
		FROM {raw:db_ships}
		WHERE xenobe = "N"
		ORDER BY character_name ASC',
		array(
			'db_ships' => $dbtables['ships']
		)
	);
	
	while ($row = $smcFunc['db_fetch_assoc']($result))
	{
		 $ships[] = $row;
	}
	$smcFunc['db_free_result']($result);
	
	$result = $smcFunc['db_query']('', '
		SELECT name, planet_id, sector_id
		FROM {raw:db_planets}
		WHERE owner = {int:ship_id}
		ORDER BY sector_id ASC',
		array(
			'db_planets' => $dbtables['planets'],
			'ship_id' => $playerinfo['ship_id']
		)
	);

	while($row = $smcFunc['db_fetch_assoc']($result))
	{
		$planets[] = $row;
	}


	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transfertype'], '<br>
							---------------------------------
						</td>
					</tr>
					<tr valign="top">
						<td>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=transfer2" method="post">
								<table width="100%">
									<tr>
										<td>
											<font size="2" face="courier new" color="#00FF00">
											', $txt['bnt_igb_toanothership'], ' :
											</font>
										</td>
										<td>
											<select class="term" name="ship_id">';

	foreach ($ships as $ship)
	{
		echo '
												<option value="', $ship['ship_id'], '">', $ship['character_name'], '</option>';
	}

	echo '
											</select>
										</td>
										<td align="right">
											<input class="term" type="submit" name="shipt" value="', $txt['bnt_igb_shiptransfer'], '">
										</td>
									</tr>
								</table>
					       </form>
					    </td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_fromplanet'], ' :<br><br>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=transfer2" method="post">
								<table width="100%">
									<tr>
										<td>
											<font size="2" face="courier new" color="#00FF00">
											', $txt['bnt_igb_source'], '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
											</font>
										</td>
										<td>
											<select class="term" name="splanet_id">';

	if (isset($planets))
	{
		foreach ($planets as $planet)
		{
			if (empty($planet['name']))
				$planet['name'] = $txt['bnt_igb_unnamed'];
			echo '								<option value="', $planet['planet_id'], '">', $planet['name'], ' ', $txt['bnt_igb_in'], ' ', $planet['sector_id'], '</option>';
		}
	}
	else
		echo '									<option value="none">', $txt['bnt_igb_none'], '</option>';
	
	echo '									</select>
										</td>
									</tr>
									<tr>
										<td>
											<font size="2" face="courier new" color="#00FF00">
											', $txt['bnt_igb_destination'], '
											</font>
										</td>
										<td>
											<select class="term" name="dplanet_id">';

	if (isset($planets))
	{
		foreach ($planets as $planet)
		{
			if (empty($planet['name']))
				$planet['name'] = $txt['bnt_igb_unnamed'];
			echo '								<option value="', $planet['planet_id'], '">', $planet['name'], ' ', $txt['bnt_igb_in'], ' ', $planet['sector_id'], '</option>';
		}
	}
	else
		echo '									<option value="none">', $txt['bnt_igb_none'], '</option>';
	

	echo '
											</select>
										</td>
										<td align="right">
											<input class="term" type="submit" name="planett" value="', $txt['bnt_igb_planettransfer'], '">
										</td>
									</tr>
								</table>
							</form>
						</td>
					</tr>';

	echo '			<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_conspl'], ' :<br><br>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=consolidate" method="post">
								<table width="100%">
									<tr>
										<td>
											<font size="2" face="courier new" color="#00FF00">
											', $txt['bnt_igb_destination'], '
											</font>
										</td>
										<td>
											<select class="term" name="dplanet_id">';

	if (isset($planets))
	{
		foreach ($planets as $planet)
		{
			if (empty($planet['name']))
				$planet['name'] = $txt['bnt_igb_unnamed'];
			echo '								<option value="', $planet['planet_id'], '">', $planet['name'], ' ', $txt['bnt_igb_in'], ' ', $planet['sector_id'], '</option>';
		}
	}
	else
		echo '									<option value="none">', $txt['bnt_igb_none'], '</option>';
	
	echo '
											</select>
										</td>
										<td align="right">
											<input class="term" type="submit" name="planetc" value="', $txt['bnt_igb_consolidate'], '">
										</td>
									<tr>
								</table>
					       </form>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br>
							<a href="', $scripturl, '?action=blacknova;sa=main.php">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';
}

function IGB_transfer2($playerinfo,$account)
{
	global $smcFunc, $txt, $scripturl;
	global $IGB_min_turns, $IGB_svalue, $ibank_paymentfee,  $IGB_trate;
	global $dbtables;
	
	// Player is initiating a transfer from his bank account to another ship.
	if (isset($_POST['ship_id'])) 
	{
		$ship_id = $_POST['ship_id'];
		
		if ($playerinfo['ship_id'] == $ship_id)
		{
			IGB_error($txt['bnt_igb_sendyourself'], "igb;command=transfer");
			return;
		}
		
		$result = $smcFunc['db_query']('', '
			SELECT *
			FROM {raw:db_ships}
			WHERE ship_id = {int:ship_id}
			LIMIT 1',
			array(
				'db_ships' => $dbtables['ships'],
				'ship_id' => $ship_id
			)
		);

		if($smcFunc['db_num_rows']($result) == 0)
		{
			IGB_error($txt['bnt_igb_unknowntargetship'], "igb;command=transfer");
			return;
		}

		$target = $smcFunc['db_fetch_assoc']($result);
		$smcFunc['db_free_result']($result);

		if ($target['turns_used'] < $IGB_min_turns)
		{
			$txt['bnt_igb_min_turns'] = str_replace("[igb_min_turns]", $IGB_min_turns, $txt['bnt_igb_min_turns']);
			$txt['bnt_igb_min_turns']= str_replace("[igb_target_char_name]", $target['character_name'], $txt['bnt_igb_min_turns']);
			IGB_error($txt['bnt_igb_min_turns'], "igb;command=transfer");
			return;
		}

		if ($playerinfo['turns_used'] < $IGB_min_turns)
		{
			$txt['bnt_igb_min_turns2'] = str_replace("[igb_min_turns]", $IGB_min_turns, $txt['bnt_igb_min_turns2']);
			IGB_error($txt['bnt_igb_min_turns2'], "igb;command=transfer");
			return;
		}

		if ($IGB_trate > 0)
		{
			$curtime = time();
			$curtime -= $IGB_trate * 60;
			
			$result = $smcFunc['db_query']('', '
				SELECT UNIX_TIMESTAMP(time) as time 
				FROM {raw:db_IGB_transfers}
				WHERE UNIX_TIMESTAMP(time) > {string:curtime}
				AND source_id = {int:player}
				AND dest_id = {int:target}',
				array(
					'db_IGB_transfers' => $dbtables['IGB_transfers'],
					'curtime' => $curtime,
					'player' => $playerinfo['ship_id'],
					'target' => $target['ship_id']
				)
			);

			if ($smcFunc['db_num_rows']($result) > 0)
			{
				$time = $smcFunc['db_fetch_assoc']($result);
				$smcFunc['db_free_result']($result);
				
				$difftime = ($time['time'] - $curtime) / 60;
				$txt['bnt_igb_mustwait'] = str_replace("[igb_target_char_name]", $target['character_name'], $txt['bnt_igb_mustwait']);
				$txt['bnt_igb_mustwait'] = str_replace("[igb_trate]", NUMBER($IGB_trate), $txt['bnt_igb_mustwait']);
				$txt['bnt_igb_mustwait'] = str_replace("[igb_difftime]", NUMBER($difftime), $txt['bnt_igb_mustwait']);
				IGB_error($txt['bnt_igb_mustwait'], "igb;command=transfer");
				return;
			}
		}

		echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_shiptransfer'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_igbaccount'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($account['balance']), ' C</font>
						</td>
					</tr>';

		if ($IGB_svalue == 0)
			echo '
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_maxtransfer'], '</font> :
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_unlimited'], '</font>
						</td>
					</tr>';
		else
		{
			$percent = $IGB_svalue * 100;
			$score = gen_score($playerinfo['ship_id']);
			$maxtrans = $score * $score * $IGB_svalue;

			$txt['bnt_igb_maxtransferpercent'] = str_replace("[igb_percent]", $percent, $txt['bnt_igb_maxtransferpercent']);
			echo '
					<tr valign="top">
						<td "nowrap">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_maxtransferpercent'], ' :</font>
						</td>
						<td align=right>
							<font size="2" face="courier new" color="#00FF00">', NUMBER($maxtrans), ' C</font>
						</td>
					</tr>';
		}

		$percent = $ibank_paymentfee * 100;

		$txt['bnt_igb_transferrate'] = str_replace("[igb_num_percent]", NUMBER($percent,1), $txt['bnt_igb_transferrate'] );
	
		echo '
					<tr valign="top>"
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_recipient'], ' :</font>
						</td>
						<td align=right>
							<font size="2" face="courier new" color="#00FF00">', $target['character_name'], '&nbsp;&nbsp;</font>
						</td>
					</tr>
					<tr>
						<td>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=transfer3" method="post">
								<table width="100%">
									<tr valign="top">
										<td>
											<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_seltransferamount'], ' :</font>
										</td>
										<td align="right">
											<input class="term" type="text" size="15" maxlength="20" name="amount" value="0"><br>
											<input class="term" type="submit" value="', $txt['bnt_igb_transfer'], '">
										</td>
									</tr>
									<tr>
										<td>
											<input type="hidden" name="ship_id" value="', $ship_id, '">
										</td>
									</tr>
								</table>
							</form>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">
							', $txt['bnt_igb_transferrate'], '
							</font>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=transfer">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br>
							<a href="', $scripturl, '?action=blacknova;sa=main.php">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';
	}
	else
	{
		$splanet_id = (isset($_POST['splanet_id'])) ? $_POST['splanet_id'] : '';
		$dplanet_id = (isset($_POST['dplanet_id'])) ? $_POST['dplanet_id'] : '';
		
		if ($splanet_id == $dplanet_id)
		{
			IGB_error($txt['bnt_igb_errplanetsrcanddest'], "igb;command=transfer");
			return;
		}

		$result = $smcFunc['db_query']('', '
			SELECT  name, credits, owner, sector_id, base
			FROM {raw:db_planets}
			WHERE planet_id = {int:splanet_id}
			LIMIT 1',
			array(
				'db_planets' => $dbtables['planets'],
				'splanet_id' => $splanet_id
			)
		);
		   
		if ($smcFunc['db_num_rows']($result) == 0)
		{
			IGB_error($txt['bnt_igb_errunknownplanet'], "igb;command=transfer");
			return;
		}
			
		$source = $smcFunc['db_fetch_assoc']($result);
		$smcFunc['db_free_result']($result);

		if (empty($source['name']))
			$source['name'] = $txt['bnt_igb_unnamed'];
			
		$result = $smcFunc['db_query']('', '
			SELECT  name, credits, owner, sector_id, base
			FROM {raw:db_planets}
			WHERE planet_id = {int:dplanet_id}
			LIMIT 1',
			array(
				'db_planets' => $dbtables['planets'],
				'dplanet_id' => $dplanet_id
			)
		);
		
		if ($smcFunc['db_num_rows']($result) == 0)
		{
			IGB_error($txt['bnt_igb_errunknownplanet'], "igb;command=transfer");
			return;
		}

		$dest = $smcFunc['db_fetch_assoc']($result);
		$smcFunc['db_free_result']($result);
		
		if (empty($dest['name']))
			$dest['name'] =$txt['bnt_igb_unnamed'];
			
		if ($dest['base'] == 'N')
		{
			IGB_error($txt['bnt_igb_errnobase'], "igb;command=transfer");
			return;
		}

		if ($source['owner'] != $playerinfo['ship_id'] || $dest['owner'] != $playerinfo['ship_id'])
		{
			IGB_error($txt['bnt_igb_errnotyourplanet'], "igb;command=transfer");
			return;
		}

	    $percent = $ibank_paymentfee * 100;

		$txt['bnt_igb_transferrate2'] = str_replace("[igb_num_percent]", NUMBER($percent,1), $txt['bnt_igb_transferrate2']);
		
		echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_planettransfer'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_srcplanet'], ' ', $source['name'], ' ', $txt['bnt_igb_in'], ' ', $source['sector_id'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($source['credits']), ' C</font>
						</td>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_destplanet'], ' ', $dest['name'], ' ', $txt['bnt_igb_in'], ' ', $dest['sector_id'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($dest['credits']), ' C</font>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=transfer3" method="post">
								<table>										
									<tr valign="top">
										<td>
											<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_seltransferamount'], ' :</font>
										</td>
									<tr>
										<td align="right">
											<input class="term" type="text" size="15" maxlength="20" name="amount" value="0">
											<br><input class="term" type="submit" value="', $txt['bnt_igb_transfer'], '">
										</td>
									</tr>
									<tr>
										<td>
											<input type="hidden" name="splanet_id" value="', $splanet_id, '">
											<input type="hidden" name="dplanet_id" value="', $dplanet_id, '">
										</td>
									</tr>
								</table>
							</form>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">
							', $txt['bnt_igb_transferrate2'], '
							</font>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=transfer">', $txt['bnt_igb_back'], '</a>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br>
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
						</td>
					</tr>';
	}
}

function IGB_transfer3($playerinfo,$account)
{
	global $smcFunc, $txt, $scripturl;
	global $IGB_min_turns, $IGB_svalue, $ibank_paymentfee, $IGB_trate;
	global $dbtables;
	
	
	$amount = (isset($_POST['amount'])) ? $_POST['amount'] : '';
	$amount = StripNonNum($amount);

	if ($amount < 0)
		$amount = 0;
		
	// Player is initiating a transfer from his bank account to another ship.
	if (isset($_POST['ship_id']))
	{
		//Need to check again to prevent cheating by manual posts
		$ship_id = $_POST['ship_id'];
		
		if ($playerinfo['ship_id'] == $ship_id)
		{
			IGB_error($txt['bnt_igb_sendyourself'], "igb;command=transfer");
			return;
		}
		
		$result = $smcFunc['db_query']('', '
			SELECT *
			FROM {raw:db_ships}
			WHERE ship_id = {int:ship_id}
			LIMIT 1',
			array(
				'db_ships' => $dbtables['ships'],
				'ship_id' => $ship_id
			)
		);

		if ($smcFunc['db_num_rows']($result) == 0)
		{
			IGB_error($txt['bnt_igb_unknowntargetship'], "igb;command=transfer");
			return;
		}

		$target = $smcFunc['db_fetch_assoc']($result);
		$smcFunc['db_free_result']($result);

		if ($target['turns_used'] < $IGB_min_turns)
		{
			$txt['bnt_igb_min_turns'] = str_replace("[igb_min_turns]", $IGB_min_turns, $txt['bnt_igb_min_turns']);
			$txt['bnt_igb_min_turns']= str_replace("[igb_target_char_name]", $target['character_name'], $txt['bnt_igb_min_turns']);
			IGB_error($txt['bnt_igb_min_turns'], "igb;command=transfer");
			return;
		}

		if ($playerinfo['turns_used'] < $IGB_min_turns)
		{
			$txt['bnt_igb_min_turns2'] = str_replace("[igb_min_turns]", $IGB_min_turns, $txt['bnt_igb_min_turns2']);
			IGB_error($txt['bnt_igb_min_turns2'], "igb;command=transfer");
			return;
		}

		if ($IGB_trate > 0)
		{
			$curtime = time();
			$curtime -= $IGB_trate * 60;
			
			$result = $smcFunc['db_query']('', '
				SELECT UNIX_TIMESTAMP(time) as time 
				FROM {raw:db_IGB_transfers}
				WHERE UNIX_TIMESTAMP(time) > {string:curtime}
				AND source_id = {int:player}
				AND dest_id = {int:target}',
				array(
					'db_IGB_transfers' => $dbtables['IGB_transfers'],
					'curtime' => $curtime,
					'player' => $playerinfo['ship_id'],
					'target' => $target['ship_id']
				)
			);

			if ($smcFunc['db_num_rows']($result) > 0)
			{
				$time = $smcFunc['db_fetch_assoc']($result);
				$smcFunc['db_free_result']($result);
				
				$difftime = ($time['time'] - $curtime) / 60;
				$txt['bnt_igb_mustwait'] = str_replace("[igb_target_char_name]", $target['character_name'], $txt['bnt_igb_mustwait']);
				$txt['bnt_igb_mustwait'] = str_replace("[igb_trate]", NUMBER($IGB_trate), $txt['bnt_igb_mustwait']);
				$txt['bnt_igb_mustwait'] = str_replace("[igb_difftime]", NUMBER($difftime), $txt['bnt_igb_mustwait']);
				IGB_error($txt['bnt_igb_mustwait'], "igb;command=transfer");
				return;
			}
		}	
		
		if (($amount * 1) != $amount)
		{
			IGB_error($txt['bnt_igb_invalidtransferinput'], "igb;command=transfer");
			return;
		}

		if ($amount == 0)
		{
			IGB_error($txt['bnt_igb_nozeroamount'], "igb;command=transfer");
			return;
		}

		if ($amount > $account['balance'])
		{
			IGB_error($txt['bnt_igb_notenoughcredits'], "igb;command=transfer");
			return;
		}

		if ($IGB_svalue != 0)
		{
			$percent = $IGB_svalue * 100;
			$score = gen_score($playerinfo['ship_id']);
			$maxtrans = $score * $score * $IGB_svalue;

			if ($amount > $maxtrans)
			{
				IGB_error($txt['bnt_igb_amounttoogreat'], "igb;command=transfer");
				return;
			}
		}

		$account['balance'] -= $amount;
		$amount2 = $amount * $ibank_paymentfee;
		$transfer = $amount - $amount2;

		echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transfersuccessful'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($transfer), ' ', $txt['bnt_igb_creditsto'], ' ', $target['character_name'], '</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transferamount'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transferfee'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount2), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_amounttransferred'], ' :
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($transfer), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_igbaccount'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($account['balance']), ' C</font>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';

		$update = $smcFunc['db_query']('', '
			UPDATE {raw:db_ibank_accounts}
			SET balance = balance - {float:amount}
			WHERE ship_id = {int:ship_id}',
			array(
				'db_ibank_accounts' => $dbtables['ibank_accounts'],
				'amount' => floatval($amount),
				'ship_id' => $playerinfo['ship_id']
			)
		);
		
		$update = $smcFunc['db_query']('', '
			UPDATE {raw:db_ships}
			SET credits = credits + {float:transfer}
			WHERE ship_id = {int:ship_id}',
			array(
				'db_ships' => $dbtables['ships'],
				'transfer' => floatval($transfer),
				'ship_id' => $target['ship_id']
			)
		);

		$smcFunc['db_insert']('insert',
			$dbtables['IGB_transfers'],
			array(
				'source_id' => 'int',
				'dest_id' => 'int',
				'time' => 'string'
			),
			array(
				$playerinfo['ship_id'],
				$target['ship_id'],
				Now()
			),
			''
		);
	}
	else
	{
		$splanet_id = (isset($_POST['splanet_id'])) ? $_POST['splanet_id'] : '';
		$dplanet_id = (isset($_POST['dplanet_id'])) ? $_POST['dplanet_id'] : '';
		
		if ($splanet_id == $dplanet_id)
		{
			IGB_error($txt['bnt_igb_errplanetsrcanddest'], "igb;command=transfer");
			return;
		}
			
		$result = $smcFunc['db_query']('', '
			SELECT  name, credits, owner, sector_id, base
			FROM {raw:db_planets}
			WHERE planet_id = {int:splanet_id}
			LIMIT 1',
			array(
				'db_planets' => $dbtables['planets'],
				'splanet_id' => $splanet_id
			)
		);
		   
		if ($smcFunc['db_num_rows']($result) == 0)
		{
			IGB_error($txt['bnt_igb_errunknownplanet'], "igb;command=transfer");
			return;
		}
			
		$source = $smcFunc['db_fetch_assoc']($result);
		$smcFunc['db_free_result']($result);

		if (empty($source['name']))
			$source['name'] = $txt['bnt_igb_unnamed'];
			
		$result = $smcFunc['db_query']('', '
			SELECT  name, credits, owner, sector_id, base
			FROM {raw:db_planets}
			WHERE planet_id = {int:dplanet_id}
			LIMIT 1',
			array(
				'db_planets' => $dbtables['planets'],
				'dplanet_id' => $dplanet_id
			)
		);
		
		if ($smcFunc['db_num_rows']($result) == 0)
		{
			IGB_error($txt['bnt_igb_errunknownplanet'], "igb;command=transfer");
			return;
		}

		$dest = $smcFunc['db_fetch_assoc']($result);
		$smcFunc['db_free_result']($result);
		
		if (empty($dest['name']))
			$dest['name'] =$txt['bnt_igb_unnamed'];
			
		if ($dest['base'] == 'N')
		{
			IGB_error($txt['bnt_igb_errnobase'], "igb;command=transfer");
			return;
		}

		if ($source['owner'] != $playerinfo['ship_id'] || $dest['owner'] != $playerinfo['ship_id'])
		{
			IGB_error($txt['bnt_igb_errnotyourplanet'], "igb;command=transfer");
			return;
		}

		if($amount > $source['credits'])
		{
			IGB_error($txt['bnt_igb_notenoughcredits2'], "igb;command=transfer");
			return;
		}
	  
	    $percent = $ibank_paymentfee * 100;	

		$source['credits'] -= $amount;
		$amount2 = $amount * $ibank_paymentfee;
		$transfer = $amount - $amount2;
		$dest['credits'] += $transfer;

		echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transfersuccessful'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($transfer), ' ', $txt['bnt_igb_ctransferredfrom'], ' ', $source['name'], ' ', $txt['bnt_igb_to'], ' ', $dest['name'], '</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transferamount'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transferfee'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount2), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_amounttransferred'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($transfer), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_srcplanet'], ' ', $source['name'], ' ', $txt['bnt_igb_in'], ' ', $source['sector_id'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($source['credits']), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_destplanet'], ' ', $dest['name'], ' ', $txt['bnt_igb_in'], ' ', $dest['sector_id'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($dest['credits']), ' C</font>
						</td>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';

		$update = $smcFunc['db_query']('', '
			UPDATE {raw:db_planets}
			SET credits = credits - {float:amount}
			WHERE planet_id = {int:splanet_id}',
			array(
				'db_planets' => $dbtables['planets'],
				'amount' => floatval($amount),
				'splanet_id' => $splanet_id
			)
		);
		
		$update = $smcFunc['db_query']('', '
			UPDATE {raw:db_planets}
			SET credits = credits + {float:transfer}
			WHERE planet_id = {int:dplanet_id}',
			array(
				'db_planets' => $dbtables['planets'],
				'transfer' => floatval($transfer),
				'dplanet_id' => $dplanet_id
			)
		);			
	}
}

function IGB_consolidate($playerinfo)
{
	global $txt, $scripturl;
	global $IGB_tconsolidate, $ibank_paymentfee;
	
	$dplanet_id = $_POST['dplanet_id'];
	
	$percent = $ibank_paymentfee * 100;

	$txt['bnt_igb_transferrate3'] = str_replace("[igb_num_percent]", NUMBER($percent,1), $txt['bnt_igb_transferrate3']);
	$txt['bnt_igb_transferrate3'] = str_replace("[nbplanets]", $IGB_tconsolidate, $txt['bnt_igb_transferrate3']);

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_planetconsolidate'], '<br>
							---------------------------------
						</td>
					</tr>
					<tr>
						<td>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=consolidate2" method="post">
								<table>
									<tr valign="top">
										<td colspan="2">
											<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_consolrates'], ' :
										</td>
									</tr>
									<tr valign="top">
										<td>
											<font size="2" face="courier new" color="#00FF00">
											', $txt['bnt_igb_minimum'], ' :
											<input class="term" type="text" size="15" maxlength="20" name="minimum" value="0" />
										</td>
									</tr>
									<tr valign="top">
										<td>
											<font size="2" face="courier new" color="#00FF00">
											', $txt['bnt_igb_maximum'], ' :
											<input class="term" type="text" size="15" maxlength="20" name="maximum" value="0" />
										</td>
									</tr>
									<tr>
										<td>
											<font size="2" face="courier new" color="#00FF00">
											<input class="term" type="submit" value="', $txt['bnt_igb_compute'], '" />
										</td>
									</tr>
									<tr>
										<td>
										      <input type="hidden" name="dplanet_id" value="', $dplanet_id, '" />
										</td>
									</tr>
								</table>
							</form>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transferrate3'], '
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=transfer">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';
}

function IGB_consolidate2($playerinfo)
{
	global $smcFunc, $txt, $scripturl;
	global $dbtables;
	global $IGB_tconsolidate, $ibank_paymentfee;
	
	$dplanet_id = $_POST['dplanet_id'];
	$minimum = $_POST['minimum'];
	$maximum = $_POST['maximum'];

	$result = $smcFunc['db_query']('', '
		SELECT name, credits, owner, sector_id, base
		FROM {raw:db_planets}
		WHERE planet_id = {int:dplanet_id}
		LIMIT 1',
		array(
			'db_planets' => $dbtables['planets'],
			'dplanet_id' => $dplanet_id
		)
	);
	
	if ($smcFunc['db_num_rows']($result) == 0)
	{
		IGB_error($txt['bnt_igb_errunknownplanet'], "igb;command=transfer");
		return;
	}

	$dest = $smcFunc['db_fetch_assoc']($result);
	$smcFunc['db_free_result']($result);

	if (empty($dest['name']))
		$dest['name'] = $txt['bnt_igb_unnamed'];

	if ($dest['owner'] != $playerinfo['ship_id'])
	{
		IGB_error($txt['bnt_igb_errnotyourplanet'], "igb;command=transfer");
		return;
	}

	$minimum = StripNonNum($minimum);
	$maximum = StripNonNum($maximum);

	$query = '	SELECT SUM(credits) as total, COUNT(*) as count 
				FROM ' . $dbtables['planets'] . ' 
				WHERE owner = ' . $playerinfo['ship_id'] . ' 
				AND credits != 0';

	if ($minimum != 0)
		$query .= ' AND credits >= ' . $minimum;

	if ($maximum != 0)
		$query .= ' AND credits <= ' . $maximum;

	$query .= ' AND planet_id != ' . $dplanet_id;
	
	$result = $smcFunc['db_query']('',
		$query,
		''
	);

	$amount = $smcFunc['db_fetch_assoc']($result);
	$smcFunc['db_free_result']($result);

	$fee = $ibank_paymentfee * $amount['total'];

	$tcost = ceil($amount['count'] / $IGB_tconsolidate);
	$transfer = $amount['total'] - $fee;

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_planetconsolidate'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_currentpl'], ' ', $dest['name'], ' ', $txt['bnt_igb_in'], ' ', $dest['sector_id'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($dest['credits']), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transferamount'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount['total']), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transferfee'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($fee), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_plaffected'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount['count']), '</font>
						</td>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_turncost'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($tcost), '</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_amounttransferred'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($transfer), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="right">
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=consolidate3" method="post">
								<input type="hidden" name="minimum" value="', $minimum, '"><br>
								<input type="hidden" name="maximum" value="', $maximum, '"><br>
								<input type="hidden" name="dplanet_id" value="', $dplanet_id, '">
								<input class="term" type="submit" value="', $txt['bnt_igb_consolidate'], '">
							</form>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=transfer">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align=""right"">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';
}

function IGB_consolidate3($playerinfo)
{
	global $smcFunc, $txt, $scripturl;
	global $dbtables;
	global $dplanet_id, $minimum, $maximum, $IGB_tconsolidate, $ibank_paymentfee;

	$dplanet_id = $_POST['dplanet_id'];
	$minimum = $_POST['minimum'];
	$maximum = $_POST['maximum'];
	
	$result = $smcFunc['db_query']('', '
		SELECT name, credits, owner, sector_id, base
		FROM {raw:db_planets}
		WHERE planet_id = {int:dplanet_id}
		LIMIT 1',
		array(
			'db_planets' => $dbtables['planets'],
			'dplanet_id' => $dplanet_id
		)
	);
	
	if ($smcFunc['db_num_rows']($result) == 0)
	{
		IGB_error($txt['bnt_igb_errunknownplanet'], "igb;command=transfer");
		return;
	}

	$dest = $smcFunc['db_fetch_assoc']($result);
	$smcFunc['db_free_result']($result);

	if (empty($dest['name']))
		$dest['name'] = $txt['bnt_igb_unnamed'];

	if ($dest['owner'] != $playerinfo['ship_id'])
	{
		IGB_error($txt['bnt_igb_errnotyourplanet'], "igb;command=transfer");
		return;
	}

	$minimum = StripNonNum($minimum);
	$maximum = StripNonNum($maximum);

	$query = '	SELECT SUM(credits) as total, COUNT(*) as count 
				FROM ' . $dbtables['planets'] . ' 
				WHERE owner = ' . $playerinfo['ship_id'] . ' 
				AND credits != 0';

	if ($minimum != 0)
		$query .= ' AND credits >= ' . $minimum;

	if ($maximum != 0)
		$query .= ' AND credits <= ' . $maximum;

	$query .= ' AND planet_id != ' . $dplanet_id;
	
	$result = $smcFunc['db_query']('',
		$query,
		''
	);

	$amount = $smcFunc['db_fetch_assoc']($result);
	$smcFunc['db_free_result']($result);

	$fee = $ibank_paymentfee * $amount['total'];

	$tcost = ceil($amount['count'] / $IGB_tconsolidate);
	$transfer = $amount['total'] - $fee;

	$cplanet = $transfer + $dest['credits'];

	if ($tcost > $playerinfo['turns'])
	{
		IGB_error($txt['bnt_igb_notenturns'], "igb;command=transfer");
		return;
	}

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_transfersuccessful'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_currentpl'], ' ', $dest['name'], ' ', $txt['bnt_igb_in'], ' ', $dest['sector_id'], ' : ', NUMBER($cplanet), ' C<br><br>
							', $txt['bnt_igb_turncost'], ' : ', NUMBER($tcost), '
							</font>
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align=""right"">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';

	$query = '	UPDATE ' . $dbtables['planets'] . ' 
				SET credits = 0
				WHERE owner = ' . $playerinfo['ship_id'] . ' 
				AND credits != 0';

	if ($minimum != 0)
		$query .= ' AND credits >= ' . $minimum;

	if ($maximum != 0)
		$query .= ' AND credits <= ' . $maximum;

	$query .= ' AND planet_id != ' . $dplanet_id;

	$result = $smcFunc['db_query']('',
		$query,
		''
	);
	
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_planets}
		SET credits = credits + {float:transfer}
		WHERE planet_id = {int:dplanet_id}',
		array(
			'db_planets' => $dbtables['planets'],
			'transfer' => floatval($transfer),
			'dplanet_id' => $dplanet_id
		)
	);
	
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ships}
		SET turns = turns + {int:tcost}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ships' => $dbtables['ships'],
			'tcost' => $tcost,
			'ship_id' => $playerinfo['ship_id']
		)
	);	
}

function IGB_loans($playerinfo,$account)
{
	global $smcFunc, $txt, $scripturl;
	global $ibank_loanlimit, $ibank_loanfactor, $ibank_loaninterest, $IGB_lrate;
	global $dbtables;

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loanstatus'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_shipaccount'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($playerinfo['credits']), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_currentloan'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">'. NUMBER($account['loan']), ' C</font>
						</td>
					</tr>';

	if ($account['loan'] != 0)
	{
	    $curtime = time();
		
		$result = $smcFunc['db_query']('', '
			SELECT UNIX_TIMESTAMP(loantime) AS time
			FROM {raw:db_ibank_accounts}
			WHERE ship_id = {int:ship_id}
			LIMIT 1',
			array(
				'db_ibank_accounts' => $dbtables['ibank_accounts'],
				'ship_id' => $playerinfo['ship_id']
			)
		);
	
		if ($smcFunc['db_num_rows']($result) > 0)
			$time = $smcFunc['db_fetch_assoc']($result);
			
		$smcFunc['db_free_result']($result);


		$difftime = ($curtime - $time['time']) / 60;

		echo '
					<tr valign="top">
						<td "nowrap">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loantimeleft'], ' :</font>
						</td>';

		if ($difftime > $IGB_lrate)
		{
			echo '
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loanlate'], '</font>
						</td>
					</tr>';
		}
		else
		{
			$difftime = $IGB_lrate - $difftime;
			$hours = $difftime / 60;
			$hours = (int)$hours;
			$mins = $difftime % 60;
			echo '
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', $hours, 'h ', $mins, 'm</font>
						</td>
					</tr>';
		}

		$factor = $ibank_loanfactor *=100;
		$interest = $ibank_loaninterest *=100;

		$txt['bnt_igb_loanrates'] = str_replace("[factor]", $factor, $txt['bnt_igb_loanrates']);
		$txt['bnt_igb_loanrates'] = str_replace("[interest]", $interest, $txt['bnt_igb_loanrates']);

		echo '
					<tr>
						<td>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=repay" method="post">
								<table>
									<tr valign="top">
										<td>
											<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_repayamount'], ' :
										</td>
										<td align=right>
											<input class="term" type="text" size="15" maxlength="20" name="amount" value="0"><br><br>
											<input class="term" type="submit" value="', $txt['bnt_igb_repay'], '">
										</td>
									</tr>
								</table>
							</form>
						</td>
					<tr>
						<td colspan="2" align="center"><font size="2" face="courier new" color="#00FF00">
							', $txt['bnt_igb_loanrates'], '
						</td>
					</tr>';	
	}
	else
	{
	    $percent = $ibank_loanlimit * 100;
	    $score = gen_score($playerinfo['ship_id']);
	    $maxloan = $score * $score * $ibank_loanlimit;

		$txt['bnt_igb_maxloanpercent'] = str_replace("[igb_percent]", $percent, $txt['bnt_igb_maxloanpercent']);
		
		echo '
					<tr valign="top">
						<td "nowrap">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_maxloanpercent'], ' :</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($maxloan), ' C</font>
						</td>
					</tr>';

		$factor = $ibank_loanfactor *= 100;
		$interest = $ibank_loaninterest *= 100;

		$txt['bnt_igb_loanrates'] = str_replace("[factor]", $factor, $txt['bnt_igb_loanrates']);
		$txt['bnt_igb_loanrates'] = str_replace("[interest]", $interest, $txt['bnt_igb_loanrates']);

		echo '
					<tr>
						<td>
							<form action="', $scripturl, '?action=blacknova;sa=igb;command=borrow" method="post">
								<table>
									<tr valign="top">
										<td>
											<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loanamount'], ' :</font>
										</td>
										<td align="right">
											<input class="term" type="text" size="15" maxlength="20" name="amount" value="0"><br><br>
											<input class="term" type="submit" value="', $txt['bnt_igb_borrow'], '">
										</td>
									</tr>
								</table>
							</form>
						</td>
					<tr>
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">
							', $txt['bnt_igb_loanrates'], '
							</font>
						</td>
					</tr>';
  }

  echo '
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';
}

function IGB_borrow($playerinfo,$account)
{	
	global $smcFunc, $txt, $scripturl;
	global $ibank_loanlimit, $ibank_loanfactor, $IGB_lrate;
	global $dbtables;
	
	
	$amount = $_POST['amount'];
	$amount = StripNonNum($amount);
	
	if (($amount * 1) != $amount)
	{
		IGB_error($txt['bnt_igb_invalidamount'], "igb;command=loans");
		return;
	}

	if ($amount <= 0)
	{
		IGB_error($txt['bnt_igb_invalidamount'], "igb;command=loans");
		return;
	}

	if ($account['loan'] != 0)
	{
		IGB_error($txt['bnt_igb_notwoloans'], "igb;command=loans");
		return;
	}

	$score = gen_score($playerinfo['ship_id']);
	$maxtrans = $score * $score * $ibank_loanlimit;

	if ($amount > $maxtrans)
	{
		IGB_error($txt['bnt_igb_loantoobig'], "igb;command=loans");
		return;
	}

	$amount2 = $amount * $ibank_loanfactor;
	$amount3 = $amount + $amount2;

	$hours = $IGB_lrate / 60;
	$mins = $IGB_lrate % 60;

	$txt['bnt_igb_loanreminder'] = str_replace("[hours]", $hours, $txt['bnt_igb_loanreminder']);
	$txt['bnt_igb_loanreminder']= str_replace("[mins]", $mins, $txt['bnt_igb_loanreminder']);

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_takenaloan'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loancongrats'], '</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loantransferred'], ' :</font>
						</td>
						<td "nowrap" align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loanfee'], ' :</font>
						</td>
						<td "nowrap" align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount2), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_amountowned'], ' :</font>
						</td>
						<td nowrap align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount3), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">
							---------------------------------<br><br>
							', $txt['bnt_igb_loanreminder'], '
							</font>
						</td>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';

	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ibank_accounts}
		SET loan = {float:amount3},
			loantime = NOW()
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ibank_accounts' => $dbtables['ibank_accounts'],
			'amount3' => floatval($amount3),
			'ship_id' => $playerinfo['ship_id']
		)
	);
	
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ships}
		SET credits = credits + {float:amount}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ships' => $dbtables['ships'],
			'amount' => floatval($amount),
			'ship_id' => $playerinfo['ship_id']
		)
	);
}

function IGB_repay($playerinfo,$account)
{
	global $smcFunc, $txt, $scripturl;
	global $dbtables;
	
	$amount = $_POST['amount'];
	$amount = StripNonNum($amount);
	
	if (($amount * 1) != $amount)
	{
		IGB_error($txt['bnt_igb_invalidamount'], "igb;command=loans");
		return;
	}

	if ($amount == 0)
	{
		IGB_error($txt['bnt_igb_invalidamount'], "igb;command=loans");
		return;
	}

	if ($account['loan'] == 0)
	{
		IGB_error($txt['bnt_igb_notrepay'], "igb;command=loans");
		return;
	}

	if ($amount > $account['loan'])
		$amount = $account['loan'];

	if ($amount > $playerinfo['credits'])
	{
		IGB_error($txt['bnt_igb_notenoughrepay'], "igb;command=loans");
		return;
	}

	$playerinfo['credits'] -= $amount;
	$account['loan'] -= $amount;

	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_payloan'], '<br>
							---------------------------------
							</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_loanthanks'], '</font>
						</td>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">---------------------------------</font>
						</td>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_shipaccount'], ' :</font>
						</td>
						<td "nowrap" align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($playerinfo['credits']), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_payloan'], ' :</font>
						</td>
						<td "nowrap" align="right">
							<font size="2" face="courier new" color="#00FF00">', NUMBER($amount), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td>
							<font size="2" face="courier new" color="#00FF00">', $txt['bnt_igb_currentloan'], ' :</font>
						</td>
						<td "nowrap" align="right">
							<font size="2" face="courier new" color="#00FF00">',  NUMBER($account['loan']), ' C</font>
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" align="center">
							<font size="2" face="courier new" color="#00FF00">
							---------------------------------
							</font>
						</td>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00">
							<a href="', $scripturl, '?action=blacknova;sa=igb;command=login">', $txt['bnt_igb_back'], '</a>
							</font>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;
							<a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
							</font>
						</td>
					</tr>';

	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ibank_accounts}
		SET loan = loan - {float:amount},
			loantime = {string:loantime}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ibank_accounts' => $dbtables['ibank_accounts'],
			'amount' => floatval($amount),
			'loantime' => $account['loantime'],
			'ship_id' => $playerinfo['ship_id']
		)
	);
	
	$update = $smcFunc['db_query']('', '
		UPDATE {raw:db_ships}
		SET credits = credits - {float:amount}
		WHERE ship_id = {int:ship_id}',
		array(
			'db_ships' => $dbtables['ships'],
			'amount' => floatval($amount),
			'ship_id' => $playerinfo['ship_id']
		)
	);				
}

function IGB_error($errmsg, $backlink, $title = "Error!")
{
	global $txt, $scripturl, $settings;

	$title = $txt['bnt_igb_igberrreport'];
	
	echo '
					<tr>
						<td colspan="2" align="center" valign="top">
							<font size="2" face="courier new" color="#00FF00">', $title, '<br>
							---------------------------------
						</td>
					</tr>
					<tr valign=top>
						<td colspan="2" align=center>
							<font size="2" face="courier new" color="#00FF00">', $errmsg, '
						</td>
					</tr>
					<tr valign="bottom">
						<td>
							<font size="2" face="courier new" color="#00FF00"><a href="', $scripturl, '?action=blacknova;sa=', $backlink, '">', $txt['bnt_igb_back'], '</a>
						</td>
						<td align="right">
							<font size="2" face="courier new" color="#00FF00">&nbsp;<br><a href="', $scripturl, '?action=blacknova;sa=main">', $txt['bnt_igb_logout'], '</a>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<img src="', $settings['images_url'], '/bnt/div2.gif" />
	</center>';
	return;
}

function StripNonNum($str)
{
	$str = (string)$str;
	$output = ereg_replace("[^0-9]","",$str);
	return $output;
}

?>
